package thread;
//卖火车票的例子
public class TestThread4 implements Runnable{
    //票数
    private int ticketNums = 10;
    @Override
    public void run() {
        while (true) {
            if (ticketNums<=0) {
                break;
            }
            try {
                //添加了一个延时200毫秒
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"--->拿到了第"+ticketNums+"票");
        }
    }

    public static void main(String[] args) {
        TestThread4 tick = new TestThread4();
        new Thread(tick,"华子").start();
        new Thread(tick,"张旭").start();
        new Thread(tick,"华华").start();
    }
}
